#include <scanner/parser.h>
#include <iostream>
#include <crtdbg.h>

#include <sstream>

int main()
try
{
    _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );

    std::istringstream s("2208 0 obj <</Linearized 1/L 505459/O 2214/E 10834/N 30/T 461250/H [ 1754 859]>>endobj");

    Pdf::Parser parser( &s );

    {
        Pdf::Integer::Ptr iObj = parser.read<Pdf::Integer>();
        assert( iObj != 0 );
        assert( iObj->get() == 2208 );
    }
    {
        Pdf::Integer::Ptr iObj = parser.read<Pdf::Integer>();
        assert( iObj != 0 );
        assert( iObj->get() == 0 );
    }
    {
        Pdf::Keyword::Ptr kObj = parser.read<Pdf::Keyword>();
        assert( kObj != 0 );
        assert( kObj->get() == "obj" );
    }
    {
        Pdf::Dictionary::Ptr dObj = parser.read<Pdf::Dictionary>();
        assert( dObj != 0 );
        {
            Pdf::Integer::Ptr iObj = dObj->get<Pdf::Integer>("Linearized");
            assert( iObj != 0 );
            assert( iObj->get() == 1 );
        }
        {
            Pdf::Integer::Ptr iObj = dObj->get<Pdf::Integer>("L");
            assert( iObj != 0 );
            assert( iObj->get() == 505459 );
        }
        {
            Pdf::Integer::Ptr iObj = dObj->get<Pdf::Integer>("O");
            assert( iObj != 0 );
            assert( iObj->get() == 2214 );
        }
        {
            Pdf::Integer::Ptr iObj = dObj->get<Pdf::Integer>("E");
            assert( iObj != 0 );
            assert( iObj->get() == 10834 );
        }
        {
            Pdf::Integer::Ptr iObj = dObj->get<Pdf::Integer>("N");
            assert( iObj != 0 );
            assert( iObj->get() == 30 );
        }
        {
            Pdf::Integer::Ptr iObj = dObj->get<Pdf::Integer>("T");
            assert( iObj != 0 );
            assert( iObj->get() == 461250 );
        }
        {
            Pdf::Array::Ptr aObj = dObj->get<Pdf::Array>("H");
            assert( aObj != 0 );
            assert( aObj->count() == 2 );
            {
                Pdf::Integer::Ptr iObj = aObj->get<Pdf::Integer>(0);
                assert( iObj != 0 );
                assert( iObj->get() == 1754 );
            }
            {
                Pdf::Integer::Ptr iObj = aObj->get<Pdf::Integer>(1);
                assert( iObj != 0 );
                assert( iObj->get() == 859 );
            }
        }
    }
    {
        Pdf::Keyword::Ptr kObj = parser.read<Pdf::Keyword>();
        assert( kObj != 0 );
        assert( kObj->get() == "endobj" );
    }
}
catch (std::exception &e)
{
    std::cerr << e.what() << std::endl;
}